from typing import *


class Solution:
    def countAlternatingSubarrays(self, nums: List[int]) -> int:
        l, ans = 1, 1
        for i in range(1, len(nums)):
            if nums[i] != nums[i - 1]:
                l += 1
            else:
                l = 1
            ans += l
        return ans
